package com.witframework.web.tag.fieldsettag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;


public class LegendTag extends BodyTagSupport
{
  private String sCaption = null;
  private String align = null;
  private String accesskey = null;
  PageContext pageContext;

  public void setPageContext(PageContext paramPageContext)
  {
    this.pageContext = paramPageContext;
  }

  public PageContext getPageContext()
  {
    return this.pageContext;
  }

  public void setAlign(String paramString)
  {
    this.align = paramString;
  }

  public String getAlign()
  {
    return this.align;
  }

  public void setAccesskey(String paramString)
  {
    this.accesskey = paramString;
  }

  public String getAccesskey()
  {
    return this.accesskey;
  }

  public int doAfterBody()
    throws JspException
  {
    BodyContent localBodyContent = getBodyContent();
    if (localBodyContent == null)
    {
      this.sCaption = "";
    }
    else
    {
      this.sCaption = localBodyContent.getString();
      localBodyContent.clearBody();
    }
    return 0;
  }

  public int doEndTag()
    throws JspException
  {
    FieldsetTag localFieldsetTag = (FieldsetTag)findAncestorWithClass(this, FieldsetTag.class);
    if (localFieldsetTag == null)
      throw new JspException("legend tag: could not find ancestor fieldset");
    StringBuffer localStringBuffer = new StringBuffer("");
    localStringBuffer.append("<legend");
    if (this.align != null)
    {
      localStringBuffer.append(" align=\"");
      localStringBuffer.append(this.align);
      localStringBuffer.append("\"");
    }
    if (this.accesskey != null)
    {
      localStringBuffer.append(" accesskey=\"");
      localStringBuffer.append(this.accesskey);
      localStringBuffer.append("\"");
    }
    localStringBuffer.append(">");
    localStringBuffer.append(this.sCaption);
    localStringBuffer.append("</legend>\n");
    localFieldsetTag.setLegend(localStringBuffer.toString());
    dropData();
    return 6;
  }

  public void release()
  {
    dropData();
  }

  private void dropData()
  {
    this.align = null;
    this.accesskey = null;
  }
}
